﻿using System.Windows;
using System.Windows.Controls;
using Uipath_License.Tools;

namespace Uipath_License.Uc
{
    /// <summary>
    /// Activation_Request.xaml 的交互逻辑
    /// </summary>
    public partial class UC_Activation_Request : UserControl
    {
        public UC_Activation_Request()
        {
            InitializeComponent();
            Return.IsEnabled = false;
            Step_TextBox_0.Visibility = Visibility.Visible;
        }
        Uipath_LicenseHelper licenseHelper = new Uipath_LicenseHelper();
        private void Continue_Click(object sender, RoutedEventArgs e)
        {
            TeEventProcessing();
            Step.Next();
            Return.IsEnabled = true;
            if (Continue_Text.Text.Equals("激活"))
            {
                //激活
            }
            if (Step.StepIndex == 3)
            {
                Continue_Text.Text = "激活";
            }
            InterfaceDealwith();
        }

        private void Return_Click(object sender, RoutedEventArgs e)
        {
            Continue_Text.Text = "继续";
            Step.Prev();
            if (Step.StepIndex == 0)
            {
                Return.IsEnabled = false;
            }
            InterfaceDealwith();
        }

        public void TeEventProcessing()
        {
            switch (Step.StepIndex)
            {
                case 0:
                    string res = licenseHelper.OfflineLicenseGenerated(Step_TextBox_0.Text);
                    Step_TextBox_1.Text= res.Replace(" ","");
                    break;
                case 1:
                    
                    break;
                case 2:
                    
                    break;
                case 3:
                    string res3 = licenseHelper.OfflineActivation(Step_TextBox_3.Text);
                    HandyControl.Controls.MessageBox.Info(res3);
                    break;
            }
        }


        public void InterfaceDealwith()
        {
            switch (Step.StepIndex)
            {
                case 0:
                    Step_TextBlock_0.Visibility = Visibility.Visible;
                    Step_TextBox_0.Visibility = Visibility.Visible;
                    Step_TextBlock_1.Visibility = Visibility.Collapsed;
                    Step_TextBox_1.Visibility = Visibility.Collapsed;
                    Step_TextBlock_2.Visibility = Visibility.Collapsed;
                    Step_TextBlock_3.Visibility = Visibility.Collapsed;
                    break;
                case 1:
                    Step_TextBlock_0.Visibility = Visibility.Collapsed;
                    Step_TextBox_0.Visibility = Visibility.Collapsed;
                    Step_TextBlock_1.Visibility = Visibility.Visible;
                    Step_TextBox_1.Visibility = Visibility.Visible;
                    Step_TextBlock_2.Visibility = Visibility.Collapsed;
                    Step_TextBlock_3.Visibility = Visibility.Collapsed;

                    break;
                case 2:
                    Step_TextBlock_0.Visibility = Visibility.Collapsed;
                    Step_TextBlock_1.Visibility = Visibility.Collapsed;
                    Step_TextBox_1.Visibility= Visibility.Collapsed;
                    Step_TextBlock_2.Visibility = Visibility.Visible;
                    Step_TextBlock_3.Visibility = Visibility.Collapsed;
                    Step_TextBox_3.Visibility = Visibility.Collapsed;
                    break;
                case 3:
                    Step_TextBlock_0.Visibility = Visibility.Collapsed;
                    Step_TextBlock_1.Visibility = Visibility.Collapsed;
                    Step_TextBlock_2.Visibility = Visibility.Collapsed;
                    Step_TextBlock_3.Visibility = Visibility.Visible;
                    Step_TextBox_3.Visibility = Visibility.Visible;
                    break;
            }
        }
    }
}
